package com.yuejian_06.yuejian_06.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.yuejian_06.yuejian_06.Listener.MeListener;
import com.yuejian_06.yuejian_06.R;
import com.yuejian_06.yuejian_06.adapter.FollowAdapter;
import com.yuejian_06.yuejian_06.adapter.PostAdapter;
import com.yuejian_06.yuejian_06.bean.FollowListBean;
import com.yuejian_06.yuejian_06.bean.PostListBean;
import com.yuejian_06.yuejian_06.bean.SuccessBean;
import com.yuejian_06.yuejian_06.bean.UserUpdateBean;
import com.yuejian_06.yuejian_06.model.MeModel;

import java.util.List;

public class FollowListActivity extends BaseActivity {

    private RecyclerView recyclerView;
    private SwipeRefreshLayout activity_follow_list;
    @Override
    void initViews() {

    }

    @Override
    void initEvents() {

    }

    @Override
    void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_follow_list);
        recyclerView = (RecyclerView) findViewById(R.id.fl_rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(FollowListActivity.this));

        MeModel meModel = new MeModel();
        meModel.getFollowList(getUser_id(),meListener);

        Intent intent = getIntent();
        String follow_i = intent.getStringExtra("follow_id");
        if(null!=follow_i) {
            AlertDialog.Builder builder = new AlertDialog.Builder(FollowListActivity.this);
            builder.setIcon(R.drawable.heart_p);
            builder.setTitle(R.string.del);
            builder.setMessage(R.string.del_follow);
            builder.setPositiveButton(R.string.postive_button, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Intent intent = getIntent();
                    String follow_i = intent.getStringExtra("follow_id");
                    String follow_id = follow_i;
                    MeModel meModel = new MeModel();
                    meModel.getDelFollow(follow_id,meListenerdel);
                }
            });

            builder.setNegativeButton(R.string.negative_button, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Toast.makeText(FollowListActivity.this,"已经取消",Toast.LENGTH_SHORT).show();
                }
            });

            builder.setCancelable(false);
            AlertDialog dialog=builder.create();
            dialog.show();
        }

        //下拉刷新
        activity_follow_list = (SwipeRefreshLayout) findViewById(R.id.activity_follow_list);
        activity_follow_list.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override public void onRefresh() {
                //重新获取数据
                MeModel meModel = new MeModel();
                meModel.getFollowList(getUser_id(),meListener1);
                //获取完成
                activity_follow_list.setRefreshing(false);
            }
        });

    }

    private MeListener<List<FollowListBean>> meListener = new MeListener<List<FollowListBean>>() {
        @Override
        public void onResponse(List<FollowListBean> o) {
            List<FollowListBean> res=o;
            List<FollowListBean> mDataList =(List) res;
            recyclerView.setAdapter(new FollowAdapter(FollowListActivity.this,mDataList));
        }

        @Override
        public void onFail(String msg) {

        }
    };


    private MeListener<SuccessBean> meListenerdel = new MeListener<SuccessBean>() {
        @Override
        public void onResponse(SuccessBean o) {
            Toast.makeText(FollowListActivity.this,"取消关注成功",Toast.LENGTH_SHORT).show();
        }
        @Override
        public void onFail(String msg) {
            Toast.makeText(FollowListActivity.this,"取消关注失败",Toast.LENGTH_SHORT).show();
        }
    };




    private MeListener<List<FollowListBean>> meListener1 = new MeListener<List<FollowListBean>>() {
        @Override
        public void onResponse(List<FollowListBean> o) {
            List<FollowListBean> res=o;
            List<FollowListBean> mDataList =(List) res;
            recyclerView.setAdapter(new FollowAdapter(FollowListActivity.this,mDataList));
            Toast.makeText(FollowListActivity.this,"关注刷新成功",Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onFail(String msg) {

        }
    };


}
